1 module hunt.templates.element; 2 3 import std.string; 4 import std.variant; 5 import std.json; 6 import hunt.templates.rule; 7 8 class Element 9 { 10 Type type; 11 string inner; 12 Element[] children; 13 14 this(const Type mtype) 15 { 16 type = mtype; 17 } 18 19 this(const Type mtype, const string minner) 20 { 21 type = mtype; 22 inner = minner; 23 } 24 }; 25 26 class ElementString : Element 27 { 28 string text; 29 30 this(const string mtext) 31 { 32 super(Type.String); 33 text = mtext; 34 } 35 }; 36 37 class ElementComment : Element 38 { 39 string text; 40 41 this(const string mtext) 42 { 43 super(Type.Comment); 44 text = mtext; 45 } 46 }; 47 48 class ElementExpression : Element 49 { 50 Function func; 51 ElementExpression[] args; 52 string command; 53 JSONValue result; 54 55 this() 56 { 57 super(Type.Expression); 58 func = Function.ReadJson; 59 } 60 61 this(const Function function_) 62 { 63 super(Type.Expression); 64 func = function_; 65 } 66 }; 67 68 class ElementLoop : Element 69 { 70 Loop loop; 71 string key; 72 string value; 73 ElementExpression list; 74 75 this(const Loop loop_, const string mvalue, ElementExpression mlist, const string inner) 76 { 77 super(Type.Loop, inner); 78 loop = loop_; 79 value = mvalue; 80 list = mlist; 81 } 82 83 this(const Loop loop_, const string mkey, const string mvalue, 84 ElementExpression mlist, string inner) 85 { 86 super(Type.Loop, inner); 87 loop = loop_; 88 key = mkey; 89 value = mvalue; 90 list = mlist; 91 } 92 }; 93 94 class ElementConditionContainer : Element 95 { 96 this() 97 { 98 super(Type.Condition); 99 } 100 }; 101 102 class ElementConditionBranch : Element 103 { 104 Condition condition_type; 105 ElementExpression condition; 106 107 this(const string inner, const Condition m_condition_type) 108 { 109 super(Type.ConditionBranch, inner); 110 condition_type = m_condition_type; 111 condition = new ElementExpression(); 112 } 113 114 this(const string inner, const Condition m_condition_type, ElementExpression m_condition) 115 { 116 super(Type.ConditionBranch, inner); 117 condition_type = m_condition_type; 118 condition = m_condition; 119 } 120 };